package com.itcast.springboot.controller;

import com.itcast.springboot.bean.Admin;
import com.itcast.springboot.bean.CommonResult;
import com.itcast.springboot.bean.Forward;
import com.itcast.springboot.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理员相关的请求")
@RestController
@CrossOrigin
public class AdminController {

    @Resource
    AdminService adminService;

    //通过account查询管理员
    @ApiOperation("通过account查询管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户")
    })
    @GetMapping("/admin/{account}")
    public Admin getAdminByAcc(@PathVariable("account") String account) {
        return adminService.getAdminByAcc(account);
    }

    //判断账号密码是否正确
    @ApiOperation("判断账号密码是否正确")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户"),
            @ApiImplicitParam(name = "password", value = "密码"),
    })
    @GetMapping("/admin/state/{account}/{password}")
    public CommonResult getAdminState(@PathVariable("account") String account, @PathVariable("password") String password) {
        return adminService.getAdminState(account, password);
    }

    //改
    @ApiOperation("修改密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户"),
            @ApiImplicitParam(name = "password", value = "密码")
    })
    @PutMapping("/admin/{account}/{password}")
    public Integer updatePassword(@PathVariable("account") String account,
                                  @PathVariable("password") String password){
        return adminService.updatePassword(account, password);
    }
}
